<style lang="less">
    @import './login.less';
</style>
<template>
    <div class="login">
        <div class="login-con">
            <Card icon="log-in" title="欢迎登录" :bordered="false">
                <div class="form-con">
                    <login-form @on-success-valid="handleSubmit"></login-form>
                    <p class="login-tip">输入任意用户名和密码即可</p>
                </div>
            </Card>
        </div>
    </div>
</template>

<script>
    import LoginForm from '_c/login-form'

    export default {
        components: {
            LoginForm
        },
        methods: {
            handleSubmit({userName, password}) {
                let data = {
                    username: userName,
                    password: password,
                    grant_type: "password",
                    scope: "select",
                    client_id: "client",
                    client_secret: "client"
                }
                const msg = this.$Message.loading({
                    content: '正在登陆，请稍后！！！',
                    duration: 0
                });
                this.http.auth("/oauth/token", this.qs.stringify(data)).then(res => {
                    if (res.data) {
                        this.$store.commit("setToken", res.data.token)
                        this.$store.commit("setUser", res.data.user)
                        setTimeout(msg, 0);
                        this.MySocket.commit("startsocket", this.$store.state.user.user.userId)
                        if (res.data.user.AuthorityList.includes("admin")) {
                            this.$router.push({name: this.$config.homeName})
                        } else {
                            this.$router.push("/teacherSupervisionHome")
                        }

                    }
                }).catch(res => {
                    setTimeout(msg, 0);
                    this.$Modal.error({
                        title: "登陆失败",
                        content: "登陆失败！！！"
                    });
                })
            }
        }
    }
</script>

<style>

</style>
